<?php
$this->setLayout('template'.DS.'default.phtml');

$this->startBlock('topbar');
echo $this->navigation->toHtml();
$this->endBlock();

$this->startBlock();
echo $this->toolbar->toHtml();
echo $this->form->toHtml();
?>
<script language="javascript" type="text/javascript">
$(function(){
	$('#parent_id').change(function(){
		changeParent();
	});

	if($('#parent_id').val() != '0'){
		changeParent();
	}
});

function changeParent(){
	var v = $('#parent_id').val();
	if(v == '0'){
		$('input:checked').each(function(){
			if($(this).attr('disabled')){
				$(this).removeAttr('checked').removeAttr('disabled')
					   .next().css('font-weight', 'normal');
			}
		});
	}else{
		Kdf.Ajax.loadJson({
			url:'<?php echo $this->getUrl(NULL, 'role-actions')?>',
			data:{roleid:v},
			success:function(json){
				$('input:checked').each(function(){
					if($(this).attr('disabled')){
						$(this).removeAttr('checked').removeAttr('disabled')
							   .next().css('font-weight', 'normal');
					}
				});
								
				for(var i = 0; i < json.length; i++){
					$('input:checkbox').each(function(){
						if($(this).val() == json[i].id){
							$(this).attr({checked:true, disabled:true})
								   .next().css('font-weight', '700');
							return false;
						}
					});
				}
			}
		});
	}
}
</script>
<?php
$this->endBlock();